{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Please set the ROOT_DIR in utils.py firstly.\n",
    "import os\n",
    "from utils import *\n",
    "import urllib\n",
    "\n",
    "def get_url_file(url, data_dir):\n",
    "    if not os.path.exists(data_dir) :\n",
    "        os.makedirs(data_dir)\n",
    "    filename = url.split('/')[-1]\n",
    "    filepath = data_dir + os.sep + filename\n",
    "    if os.path.exists(filepath):\n",
    "        print(filepath + \" has already exist.\")\n",
    "    else:\n",
    "        print(\"Downloading \" + filepath)\n",
    "        urllib.request.urlretrieve(url, filename = filepath)\n",
    "\n",
    "get_url_file(\"http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data\", ROOT_DIR + \"filesys\")\n",
    "get_url_file(\"http://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-white.csv\", ROOT_DIR + \"filesys\")\n",
    "get_url_file(\"http://files.grouplens.org/datasets/movielens/ml-100k/u.data\", ROOT_DIR + \"filesys\")\n",
    "get_url_file(\"http://archive.ics.uci.edu/ml/machine-learning-databases/00267/data_banknote_authentication.txt\", ROOT_DIR + \"banknote\")\n",
    "get_url_file(\"http://archive.ics.uci.edu/ml/machine-learning-databases/mushroom/agaricus-lepiota.data\", ROOT_DIR + \"mushroom\")\n",
    "get_url_file(\"http://archive.ics.uci.edu/ml/machine-learning-databases/statlog/german/german.data\", ROOT_DIR + \"german_credit\")\n",
    "get_url_file(\"http://alink-release.oss-cn-beijing.aliyuncs.com/data-files/action_log.csv\", ROOT_DIR + \"tmall\")\n",
    "get_url_file(\"http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data\", ROOT_DIR + \"iris\")\n",
    "\n",
    "get_url_file(\"http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz\", ROOT_DIR + \"mnist\")\n",
    "get_url_file(\"http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz\", ROOT_DIR + \"mnist\")\n",
    "get_url_file(\"http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz\", ROOT_DIR + \"mnist\")\n",
    "get_url_file(\"http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz\", ROOT_DIR + \"mnist\")\n",
    "\n",
    "get_url_file(\"http://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-white.csv\", ROOT_DIR + \"wine\")\n",
    "get_url_file(\"http://files.grouplens.org/datasets/movielens/ml-100k/u.item\", ROOT_DIR + \"movielens\" + os.sep + \"ml-100k\")\n",
    "get_url_file(\"http://files.grouplens.org/datasets/movielens/ml-100k/u.user\", ROOT_DIR + \"movielens\" + os.sep + \"ml-100k\")\n",
    "get_url_file(\"http://files.grouplens.org/datasets/movielens/ml-100k/u.data\", ROOT_DIR + \"movielens\" + os.sep + \"ml-100k\")\n",
    "get_url_file(\"http://files.grouplens.org/datasets/movielens/ml-100k/ua.base\", ROOT_DIR + \"movielens\" + os.sep + \"ml-100k\")\n",
    "get_url_file(\"http://files.grouplens.org/datasets/movielens/ml-100k/ua.test\", ROOT_DIR + \"movielens\" + os.sep + \"ml-100k\")\n",
    "\n",
    "wordvec_dir = ROOT_DIR + \"wordvec\"\n",
    "if not os.path.exists(wordvec_dir + os.sep + \"三国演义.txt\") :\n",
    "    get_url_file(\"https://raw.githubusercontent.com/tennessine/corpus/master/%E4%B8%89%E5%9B%BD%E6%BC%94%E4%B9%89.txt\", wordvec_dir)\n",
    "    os.rename(wordvec_dir + os.sep + \"%E4%B8%89%E5%9B%BD%E6%BC%94%E4%B9%89.txt\", wordvec_dir + os.sep + \"三国演义.txt\")\n",
    "\n",
    "news_dir = ROOT_DIR + \"news_toutiao\"\n",
    "get_url_file(\"https://github.com/BenDerPan/toutiao-text-classfication-dataset/raw/master/toutiao_cat_data.txt.zip\", news_dir)\n",
    "import zipfile\n",
    "if not os.path.exists(news_dir + os.sep + \"toutiao_cat_data.txt\") :\n",
    "    with zipfile.ZipFile(news_dir + os.sep + \"toutiao_cat_data.txt.zip\", 'r') as zipf:\n",
    "        zipf.extractall(news_dir)\n",
    "  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
